/*
 * HangtenApp.java
 *
 * Created on March 27, 2005, 1:03 AM
 */

package tools;

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;
import java.util.Map;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;

/**
 *
 * @author Keith
 */
public class HangtenApp extends JPanel {
  
  private Map actions;
  private JTabbedPane tabPane = new JTabbedPane();

  public HangtenApp() {
		class FileSetPanelAction implements ActionListener {
			private FileSetPanel fileSetPanel;

			public FileSetPanelAction( FileSetPanel fsp ){
				fileSetPanel = fsp;
			}

			public void actionPerformed( ActionEvent evt ){
				System.out.println( ((Component)evt.getSource()).getName() + ": ActionPerformed" );
//				BivioClubExportModel bce = new BivioClubExportModel( fileSetPanel.getBivioDataFileName() );
//				bce.process();

//				WebExtractorModel we = new WebExtractorModel( fileSetPanel.getWebExtractorFileName() );
//				we.process();
			}
		}

    setLayout( new BorderLayout() );

    add( tabPane, BorderLayout.CENTER );

    FileSetPanel fsp;
		fsp = new FileSetPanel();
		fsp.setBivioDataFileName( "D:\\Research\\hangten\\clubexp.xml" );
		fsp.setReportDefinitionFileName( "D:\\Research\\hangten\\clubrpt.xsl" );
		fsp.setWebExtractorFileName( "D:\\Research\\hangten\\webextractor.xml" );
		tabPane.add( fsp );
		fsp.addActionListener( new FileSetPanelAction( fsp ) );

		JPanel p = new JPanel();
		p.setName( "Query Parameters" );
		tabPane.add( p );

		p = new JPanel();
		p.setName( "Query Web" );
		tabPane.add( p );

		p = new JPanel();
		p.setName( "Data Explorer" );
		tabPane.add( p );

		p = new JPanel();
		p.setName( "Generate Report" );
		tabPane.add( p );

//		p = new HangtenAppConfig();
//		p.setName( "Configuration" );
//		tabPane.add( p );

    Component[] c = tabPane.getComponents();
    ComponentListener cl = new ComponentAdapter(){
      public void componentHidden(ComponentEvent e){
//        System.out.println( "Hidden: " + e.getComponent().getName() );
        setActions( null );
      }

      public void componentShown(ComponentEvent e){
//        System.out.println( "Shown: " + e.getComponent().getName() );
        Object o = (Object)e.getSource();
        Map m = null;

        if ( o instanceof ProcessPanel ){
          ProcessPanel p = (ProcessPanel)o;

          m = p.getActions();
        }

        setActions( m );
      }
    };

    for ( int i = 0; i < c.length; i++ ){
      c[ i ].addComponentListener( cl );
    }
  }

  public Map getActions() {
    return actions;
  }

  public void setActions( Map newActions) {
    Map  oldActions = actions;
    this.actions = newActions;
    firePropertyChange("actions", oldActions, newActions);
  }
}
